import os

def generate_sim(samplesize, dbtype):
    from simdat import simdat
    simdat(dbtype, samplesize, None, ".", 90000000, "dummy")

def load_sim(samplesize, dbname, dbtype, alleletype, jobs, recreate, shard):
    from load_dataset import load_dataset
    dataset = "sim"+str(samplesize)
    load_dataset(dataset, dbname, alleletype, jobs, recreate, shard, False)

if __name__ == '__main__':
    import sys, os
    usr = os.popen('whoami').read().strip()
    from optparse import OptionParser
    usage = "'%prog [-a alleletype] [-j jobs] [-n] [-s] [-t] [-y] samplesize dname dbtype'. Using the value dbtype_" + usr + " for db is recommended, where dbtype can be either 'affy6' or 'illumina'. Alleletype option is only required if dbtype is 'illumina', with possible values 'forward' and 'top'."
    parser = OptionParser(usage=usage)
    parser.add_option("-a", "--allele-type", action="store", type="string", dest="alleletype", help="allele type")
    parser.add_option("-j", "--jobs", action="store", type="int", dest="jobs", help="number of jobs to run in parallel")
    parser.add_option("-n", "--no-recreate", action="store_false", dest="recreate", help="do not recreate schema")
    parser.add_option("-s", "--sharding", action="store_true", dest="shard", help="use geno table sharding")
    parser.add_option("-y", "--recreate", action="store_true", dest="recreate", help="delete schema and recreate")
    parser.set_defaults(jobs=1)
    (options, args) = parser.parse_args()

    if len(args) != 3:
        print "incorrect number of arguments"
        parser.print_help()
        sys.exit(1)

    samplesize = int(args[0])
    dbname = args[1]
    dbtype = args[2]

    generate_sim(samplesize, dbtype)
    load_sim(samplesize, dbname, dbtype, options.alleletype, options.jobs, options.recreate, options.shard)
